home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / toolbar-x.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-26  |  22.4 KB  |  812 lines

  1. /* toolbar implementation -- X interface.
  2.    Copyright (C) 1995 Board of Trustees, University of Illinois.
  3.    Copyright (C) 1995 Sun Microsystems.
  4.  
  5. This file is part of XEmacs.
  6.  
  7. XEmacs is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with XEmacs; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* Synched up with: Not in FSF. */
  22.  
  23. #include <config.h>
  24. #include "lisp.h"
  25.  
  26. #include "device-x.h"
  27. #include "faces.h"
  28. #include "frame-x.h"
  29. #include "glyphs-x.h"
  30. #include "objects-x.h"
  31. #include "toolbar.h"
  32. #include "window.h"
  33. #include "xgccache.h"
  34. #include "EmacsFrame.h"
  35. #include "EmacsFrameP.h"
  36. #include "EmacsManager.h"
  37.  
  38. static void
  39. x_draw_blank_toolbar_button (struct frame *f, int x, int y, int width,
  40.                  int height, int threed)
  41. {
  42.   struct device *d = XDEVICE (f->device);
  43.   EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
  44.   int shadow_thickness = ef->emacs_frame.toolbar_shadow_thickness;
  45.  
  46.   Display *dpy = DEVICE_X_DISPLAY (d);
  47.   Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
  48.   GC top_shadow_gc, bottom_shadow_gc, background_gc;
  49.  
  50.   background_gc = FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
  51.  
  52.   if (threed)
  53.     {
  54.       top_shadow_gc = FRAME_X_TOOLBAR_TOP_SHADOW_GC (f);
  55.       bottom_shadow_gc = FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f);
  56.     }
  57.   else
  58.     {
  59.       top_shadow_gc = background_gc;
  60.       bottom_shadow_gc = background_gc;
  61.     }
  62.  
  63.   /* Draw the outline. */
  64.   x_output_shadows (f, x, y, width, height, top_shadow_gc,
  65.             bottom_shadow_gc, background_gc, shadow_thickness);
  66.  
  67.   /* Blank the middle. */
  68.   XFillRectangle (dpy, x_win, background_gc, x + shadow_thickness,
  69.           y + shadow_thickness, width - shadow_thickness * 2,
  70.           height - shadow_thickness * 2);
  71. }
  72.  
  73. static void
  74. x_output_toolbar_button (struct frame *f, Lisp_Object button)
  75. {
  76.   struct device *d = XDEVICE (f->device);
  77.   EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
  78.   int shadow_thickness = ef->emacs_frame.toolbar_shadow_thickness;
  79.  
  80.   Display *dpy = DEVICE_X_DISPLAY (d);
  81.   Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
  82.   GC top_shadow_gc, bottom_shadow_gc, background_gc;
  83.   Lisp_Object instance, frame, window, glyph;
  84.   struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
  85.   struct Lisp_Image_Instance *p;
  86.   struct window *w;
  87.  
  88.   XSETFRAME (frame, f);
  89.   window = FRAME_SELECTED_WINDOW (f);
  90.   w = XWINDOW (window);
  91.  
  92.   /* See comment in x_get_button_size for the logic to determine which
  93.      glyph is to be used. */
  94.  
  95.   glyph = Qnil;
  96.   if (!NILP (w->toolbar_buttons_captioned_p))
  97.     {
  98.       if (tb->enabled && tb->down)
  99.     glyph = tb->cap_down_glyph;
  100.       else if (!tb->enabled)
  101.     glyph = tb->cap_disabled_glyph;
  102.  
  103.       if (NILP (glyph))
  104.     glyph = tb->cap_up_glyph;
  105.     }
  106.  
  107.   if (NILP (glyph))
  108.     {
  109.       if (tb->enabled && tb->down)
  110.     glyph = tb->down_glyph;
  111.       else if (!tb->enabled)
  112.     glyph = tb->disabled_glyph;
  113.     }
  114.  
  115.   if (NILP (glyph))
  116.     glyph = tb->up_glyph;
  117.  
  118.   assert (!NILP (glyph));
  119.  
  120.   if (tb->enabled)
  121.     {
  122.       if (tb->down)
  123.     {
  124.       top_shadow_gc = FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f);
  125.       bottom_shadow_gc = FRAME_X_TOOLBAR_TOP_SHADOW_GC (f);
  126.     }
  127.       else
  128.     {
  129.       top_shadow_gc = FRAME_X_TOOLBAR_TOP_SHADOW_GC (f);
  130.       bottom_shadow_gc = FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f);
  131.     }
  132.     }
  133.   else
  134.     {
  135.       top_shadow_gc = FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
  136.       bottom_shadow_gc = FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
  137.     }
  138.   background_gc = FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
  139.  
  140.   instance = glyph_image_instance (glyph, window, 1);
  141.  
  142.   /* Draw the outline. */
  143.   x_output_shadows (f, tb->x, tb->y, tb->width, tb->height, top_shadow_gc,
  144.             bottom_shadow_gc, background_gc, shadow_thickness);
  145.  
  146.   /* Clear the pixmap area. */
  147.   XFillRectangle (dpy, x_win, background_gc, tb->x + shadow_thickness,
  148.           tb->y + shadow_thickness, tb->width - shadow_thickness * 2,
  149.           tb->height - shadow_thickness * 2);
  150.  
  151.   background_gc = FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f);
  152.  
  153.   if (IMAGE_INSTANCEP (instance))
  154.     {
  155.       int width = tb->width - shadow_thickness * 2;
  156.       int height = tb->height - shadow_thickness * 2;
  157.       int x_offset = shadow_thickness;
  158.       int y_offset = shadow_thickness;
  159.  
  160.       p = XIMAGE_INSTANCE (instance);
  161.  
  162.       if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p))
  163.     {
  164.       if (width > (int) IMAGE_INSTANCE_PIXMAP_WIDTH (p))
  165.         {
  166.           x_offset += ((int) (width - IMAGE_INSTANCE_PIXMAP_WIDTH (p))
  167.                / 2);
  168.           width = IMAGE_INSTANCE_PIXMAP_WIDTH (p);
  169.         }
  170.       if (height > (int) IMAGE_INSTANCE_PIXMAP_HEIGHT (p))
  171.         {
  172.           y_offset += ((int) (height - IMAGE_INSTANCE_PIXMAP_HEIGHT (p))
  173.                / 2);
  174.           height = IMAGE_INSTANCE_PIXMAP_HEIGHT (p);
  175.         }
  176.  
  177.       x_output_x_pixmap (f, XIMAGE_INSTANCE (instance), tb->x + x_offset,
  178.                  tb->y + y_offset, 0, 0, 0, 0, width, height,
  179.                  0, 0, 0, background_gc);
  180.     }
  181.       else if (IMAGE_INSTANCE_TYPE (p) == IMAGE_TEXT)
  182.     {
  183.       /* #### We need to make the face used configurable. */
  184.       Lisp_Object font;
  185.       struct display_line dl;
  186.       struct font_metric_info fm;
  187.       Bytecount lossage;
  188.       Lisp_Object string = IMAGE_INSTANCE_TEXT_STRING (p);
  189.       emchar_dynarr *buf = Dynarr_new (Emchar);
  190.  
  191.       /* This could be true if we were called via the Expose event
  192.              handler.  Mark the button as dirty and return
  193.              immediately. */
  194.       if (f->window_face_cache_reset)
  195.         {
  196.           tb->dirty = 1;
  197.           MARK_TOOLBAR_CHANGED;
  198.           return;
  199.         }
  200.  
  201.       font = FACE_CACHE_ELEMENT_FONT (w, DEFAULT_INDEX);
  202.       DEVMETH (d, font_metric_info, (d, font, &fm));
  203.       dl.ascent = fm.ascent;
  204.       dl.descent = fm.descent;
  205.       dl.ypos = tb->y + y_offset + fm.ascent;
  206.  
  207.       if (fm.ascent + fm.descent <= height)
  208.         {
  209.           dl.ypos += (height - fm.ascent - fm.descent) / 2;
  210.           dl.clip = 0;
  211.         }
  212.       else
  213.         {
  214.           dl.clip = fm.ascent + fm.descent - height;
  215.         }
  216.  
  217.       for (lossage = 0;
  218.            lossage < string_length (XSTRING (string));
  219.            lossage++)
  220.         Dynarr_add (buf, (Emchar) string_byte (XSTRING (string), lossage));
  221.  
  222.       x_output_string (w, &dl, buf, tb->x + x_offset, 0, 0, width,
  223.                DEFAULT_INDEX, 0, 0, 0, 0);
  224.     }
  225.  
  226.       /* We silently ignore the image if it isn't a pixmap or text. */
  227.     }
  228.  
  229.   tb->dirty = 0;
  230. }
  231.  
  232. static int
  233. x_get_button_size (struct frame *f, Lisp_Object window,
  234.            struct toolbar_button *tb, int vert, int pos)
  235. {
  236.   EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
  237.   int shadow_thickness = ef->emacs_frame.toolbar_shadow_thickness;
  238.   int size;
  239.  
  240.   if (tb->blank)
  241.     {
  242.       if (!NILP (tb->down_glyph))
  243.     size = XINT (tb->down_glyph);
  244.       else
  245.     size = DEFAULT_TOOLBAR_BLANK_SIZE;
  246.     }
  247.   else
  248.     {
  249.       Lisp_Object glyph = Qnil;
  250.       struct window *w = XWINDOW (window);
  251.  
  252.       /* The selected glyph logic:
  253.  
  254.      UP:        up
  255.      DOWN:        down -> up
  256.      DISABLED:    disabled -> up
  257.      CAP-UP:    cap-up -> up
  258.      CAP-DOWN:    cap-down -> cap-up -> down -> up
  259.      CAP-DISABLED:    cap-disabled -> cap-up -> disabled -> up
  260.      */
  261.  
  262.       if (!NILP (w->toolbar_buttons_captioned_p))
  263.     {
  264.       if (tb->enabled && tb->down)
  265.         glyph = tb->cap_down_glyph;
  266.       else if (!tb->enabled)
  267.         glyph = tb->cap_disabled_glyph;
  268.  
  269.       if (NILP (glyph))
  270.         glyph = tb->cap_up_glyph;
  271.     }
  272.  
  273.       if (NILP (glyph))
  274.     {
  275.       if (tb->enabled && tb->down)
  276.         glyph = tb->down_glyph;
  277.       else if (!tb->enabled)
  278.         glyph = tb->disabled_glyph;
  279.     }
  280.  
  281.       /* The non-captioned up button is the ultimate fallback.  It is
  282.          the only one we guarantee exists. */
  283.       if (NILP (glyph))
  284.     glyph = tb->up_glyph;
  285.  
  286.       assert (!NILP (glyph));
  287.  
  288.       if (vert)
  289.     size = glyph_height (glyph, DEFAULT_INDEX, 1, window);
  290.       else
  291.     size = glyph_width (glyph, DEFAULT_INDEX, 1, window);
  292.     }
  293.  
  294.   if (!size)
  295.     {
  296.       /* If the glyph doesn't have a size we'll insert a blank
  297.          placeholder instead. */
  298.       return XINT (f->toolbar_size[pos]);
  299.     }
  300.  
  301.   size += shadow_thickness * 2;
  302.  
  303.   return (size);
  304. }
  305.  
  306. #define X_OUTPUT_BUTTONS_LOOP(left)                    \
  307.   do {                                    \
  308.     while (!NILP (button))                        \
  309.       {                                    \
  310.     struct toolbar_button *tb = XTOOLBAR_BUTTON (button);        \
  311.     int size, height, width;                    \
  312.                                     \
  313.     if (left && tb->pushright)                    \
  314.       break;                            \
  315.                                     \
  316.         size = x_get_button_size (f, window, tb, vert, pos);        \
  317.                                     \
  318.     if (vert)                            \
  319.       {                                \
  320.         width = bar_width;                        \
  321.         if (y + size > max_pixpos)                    \
  322.           height = max_pixpos - y;                    \
  323.         else                            \
  324.           height = size;                        \
  325.       }                                \
  326.     else                                \
  327.       {                                \
  328.         if (x + size > max_pixpos)                    \
  329.           width = max_pixpos - x;                    \
  330.         else                            \
  331.           width = size;                        \
  332.         height = bar_height;                    \
  333.       }                                \
  334.                                     \
  335.     if (tb->x != x                            \
  336.         || tb->y != y                        \
  337.         || tb->width != width                    \
  338.         || tb->height != height                    \
  339.         || tb->dirty)                        \
  340.       {                                \
  341.         if (width && height)                    \
  342.           {                                \
  343.         tb->x = x;                        \
  344.         tb->y = y;                        \
  345.         tb->width = width;                    \
  346.         tb->height = height;                    \
  347.                                     \
  348.                 if (tb->blank)                        \
  349.           {                            \
  350.             int threed = (EQ (Qt, tb->up_glyph) ? 1 : 0);    \
  351.             x_draw_blank_toolbar_button (f, x, y, width,    \
  352.                          height, threed);    \
  353.           }                            \
  354.             else                            \
  355.           x_output_toolbar_button (f, button);            \
  356.           }                                \
  357.       }                                \
  358.                                     \
  359.     if (vert)                            \
  360.       y += height;                            \
  361.     else                                \
  362.       x += width;                            \
  363.                                     \
  364.     if ((vert && y == max_pixpos) || (!vert && x == max_pixpos))    \
  365.       button = Qnil;                        \
  366.     else                                \
  367.       button = tb->next;                        \
  368.       }                                    \
  369.   } while (0)
  370.  
  371. #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag)            \
  372.   do {                                    \
  373.     switch (pos)                            \
  374.       {                                    \
  375.       case TOP_TOOLBAR:                            \
  376.     (frame)->top_toolbar_was_visible = flag;            \
  377.     break;                                \
  378.       case BOTTOM_TOOLBAR:                        \
  379.     (frame)->bottom_toolbar_was_visible = flag;            \
  380.     break;                                \
  381.       case LEFT_TOOLBAR:                        \
  382.     (frame)->left_toolbar_was_visible = flag;            \
  383.     break;                                \
  384.       case RIGHT_TOOLBAR:                        \
  385.     (frame)->right_toolbar_was_visible = flag;            \
  386.     break;                                \
  387.       default:                                \
  388.     abort ();                            \
  389.       }                                    \
  390.   } while (0)
  391.  
  392. static void
  393. x_output_toolbar (struct frame *f, enum toolbar_pos pos)
  394. {
  395.   struct device *d = XDEVICE (f->device);
  396.   int x, y, bar_width, bar_height, vert;
  397.   int max_pixpos, right_size, right_start, blank_size;
  398.   Lisp_Object button, window;
  399.  
  400.   get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 1);
  401.   window = FRAME_SELECTED_WINDOW (f);
  402.  
  403.   if (vert)
  404.     max_pixpos = y + bar_height;
  405.   else
  406.     max_pixpos = x + bar_width;
  407.  
  408.   button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons;
  409.   right_size = 0;
  410.  
  411.   /* First loop over all of the buttons to determine how much room we
  412.      need for left hand and right hand buttons.  This loop will also
  413.      make sure that all instances are instantiated so when we actually
  414.      output them they will come up immediately. */
  415.   while (!NILP (button))
  416.     {
  417.       struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
  418.       int size = x_get_button_size (f, window, tb, vert, pos);
  419.  
  420.       if (tb->pushright)
  421.     right_size += size;
  422.  
  423.       button = tb->next;
  424.     }
  425.  
  426.   button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons;
  427.  
  428.   /* Loop over the left buttons, updating and outputting them. */
  429.   X_OUTPUT_BUTTONS_LOOP (1);
  430.  
  431.   /* Now determine where the right buttons start. */
  432.   right_start = max_pixpos - right_size;
  433.   if (right_start < (vert ? y : x))
  434.     right_start = (vert ? y : x);
  435.  
  436.   /* Output the blank which goes from the end of the left buttons to
  437.      the start of the right. */
  438.   blank_size = right_start - (vert ? y : x);
  439.   if (blank_size)
  440.     {
  441.       int height, width;
  442.  
  443.       if (vert)
  444.     {
  445.       width = bar_width;
  446.       height = blank_size;
  447.     }
  448.       else
  449.     {
  450.       width = blank_size;
  451.       height = bar_height;
  452.     }
  453.  
  454.       x_draw_blank_toolbar_button (f, x, y, width, height, 1);
  455.  
  456.       if (vert)
  457.     y += height;
  458.       else
  459.     x += width;
  460.     }
  461.  
  462.   /* Loop over the right buttons, updating and outputting them. */
  463.   X_OUTPUT_BUTTONS_LOOP (0);
  464.  
  465.   if (!vert)
  466.     {
  467.       Lisp_Object frame;
  468.  
  469.       XSETFRAME (frame, f);
  470.       DEVMETH (d, clear_region, (frame,
  471.                  DEFAULT_INDEX, FRAME_PIXWIDTH (f) - 1, y, 1,
  472.                  bar_height));
  473.     }
  474.  
  475.   SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 1);
  476.  
  477.   XFlush (DEVICE_X_DISPLAY (d));
  478. }
  479.  
  480. static void
  481. x_clear_toolbar (struct frame *f, enum toolbar_pos pos, int thickness_change)
  482. {
  483.   Lisp_Object frame = Qnil;
  484.   struct device *d = XDEVICE (f->device);
  485.   int x, y, width, height, vert;
  486.  
  487.   get_toolbar_coords (f, pos, &x, &y, &width, &height, &vert, 1);
  488.   XSETFRAME (frame, f);
  489.  
  490.   /* The thickness_change parameter is used by the toolbar resize routines
  491.      to clear any excess toolbar if the size shrinks. */
  492.   if (thickness_change < 0)
  493.     {
  494.       if (pos == LEFT_TOOLBAR || pos == RIGHT_TOOLBAR)
  495.     {
  496.       x = x + width + thickness_change;
  497.       width = -thickness_change;
  498.     }
  499.       else
  500.     {
  501.       y = y + height + thickness_change;
  502.       height = -thickness_change;
  503.     }
  504.     }
  505.  
  506.   SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 0);
  507.  
  508.   DEVMETH (d, clear_region, (frame, DEFAULT_INDEX, x, y, width, height));
  509.   XFlush (DEVICE_X_DISPLAY (d));
  510. }
  511.  
  512. static void
  513. x_output_frame_toolbars (struct frame *f)
  514. {
  515.   assert (FRAME_IS_X (f));
  516.  
  517.   if (FRAME_TOP_TOOLBAR_VISIBLE (f))
  518.     x_output_toolbar (f, TOP_TOOLBAR);
  519.   else if (f->top_toolbar_was_visible)
  520.     x_clear_toolbar (f, TOP_TOOLBAR, 0);
  521.  
  522.   if (FRAME_BOTTOM_TOOLBAR_VISIBLE (f))
  523.     x_output_toolbar (f, BOTTOM_TOOLBAR);
  524.   else if (f->bottom_toolbar_was_visible)
  525.     x_clear_toolbar (f, BOTTOM_TOOLBAR, 0);
  526.  
  527.   if (FRAME_LEFT_TOOLBAR_VISIBLE (f))
  528.     x_output_toolbar (f, LEFT_TOOLBAR);
  529.   else if (f->left_toolbar_was_visible)
  530.     x_clear_toolbar (f, LEFT_TOOLBAR, 0);
  531.  
  532.   if (FRAME_RIGHT_TOOLBAR_VISIBLE (f))
  533.     x_output_toolbar (f, RIGHT_TOOLBAR);
  534.   else if (f->right_toolbar_was_visible)
  535.     x_clear_toolbar (f, RIGHT_TOOLBAR, 0);
  536. }
  537.  
  538. static void
  539. x_redraw_exposed_toolbar (struct frame *f, enum toolbar_pos pos, int x, int y,
  540.               int width, int height)
  541. {
  542.   int bar_x, bar_y, bar_width, bar_height, vert;
  543.   Lisp_Object button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons;
  544.  
  545.   get_toolbar_coords (f, pos, &bar_x, &bar_y, &bar_width, &bar_height,
  546.               &vert, 1);
  547.  
  548.   if (((y + height) < bar_y) || (y > (bar_y + bar_height)))
  549.     return;
  550.   if (((x + width) < bar_x) || (x > (bar_x + bar_width)))
  551.     return;
  552.  
  553.   while (!NILP (button))
  554.     {
  555.       struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
  556.  
  557.       if (vert)
  558.     {
  559.       if (((tb->y + tb->height) > y) && (tb->y < (y + height)))
  560.         tb->dirty = 1;
  561.  
  562.       /* If this is true we have gone past the exposed region. */
  563.       if (tb->y > (y + height))
  564.         break;
  565.     }
  566.       else
  567.     {
  568.       if (((tb->x + tb->width) > x) && (tb->x < (x + width)))
  569.         tb->dirty = 1;
  570.  
  571.       /* If this is true we have gone past the exposed region. */
  572.       if (tb->x > (x + width))
  573.         break;
  574.     }
  575.  
  576.       button = tb->next;
  577.     }
  578.  
  579.   /* Even if none of the buttons is in the area, the blank region at
  580.      the very least must be because the first thing we did is verify
  581.      that some portion of the toolbar is in the exposed region. */
  582.   x_output_toolbar (f, pos);
  583. }
  584.  
  585. void
  586. x_redraw_exposed_toolbars (struct frame *f, int x, int y, int width,
  587.                int height)
  588. {
  589.   assert (FRAME_IS_X (f));
  590.  
  591.   if (FRAME_TOP_TOOLBAR_VISIBLE (f))
  592.     x_redraw_exposed_toolbar (f, TOP_TOOLBAR, x, y, width, height);
  593.  
  594.   if (FRAME_BOTTOM_TOOLBAR_VISIBLE (f))
  595.     x_redraw_exposed_toolbar (f, BOTTOM_TOOLBAR, x, y, width, height);
  596.  
  597.   if (FRAME_LEFT_TOOLBAR_VISIBLE (f))
  598.     x_redraw_exposed_toolbar (f, LEFT_TOOLBAR, x, y, width, height);
  599.  
  600.   if (FRAME_RIGHT_TOOLBAR_VISIBLE (f))
  601.     x_redraw_exposed_toolbar (f, RIGHT_TOOLBAR, x, y, width, height);
  602. }
  603.  
  604. static void
  605. x_redraw_frame_toolbars (struct frame *f)
  606. {
  607.   /* There are certain startup paths that lead to update_EmacsFrame in
  608.      faces.c being called before a new frame is fully initialized.  In
  609.      particular before we have actually mapped it.  That routine can
  610.      call this one.  So, we need to make sure that the frame is
  611.      actually ready before we try and draw all over it. */
  612.  
  613.   if (XtIsRealized (FRAME_X_SHELL_WIDGET (f)))
  614.     x_redraw_exposed_toolbars (f, 0, 0, FRAME_PIXWIDTH (f),
  615.                    FRAME_PIXHEIGHT (f));
  616. }
  617.  
  618.  
  619. static void
  620. x_toolbar_size_changed_in_frame (Lisp_Object specifier, struct frame *f,
  621.                  Lisp_Object oldval)
  622. {
  623.   XtWidgetGeometry req, repl;
  624.   Lisp_Object newval;
  625.   enum toolbar_pos pos = TOP_TOOLBAR;
  626.  
  627.   if (!FRAME_IS_X (f))
  628.     return;
  629.  
  630.   if (EQ (specifier, Vtop_toolbar_height))
  631.     pos = TOP_TOOLBAR;
  632.   else if (EQ (specifier, Vbottom_toolbar_height))
  633.     pos = BOTTOM_TOOLBAR;
  634.   else if (EQ (specifier, Vleft_toolbar_width))
  635.     pos = LEFT_TOOLBAR;
  636.   else if (EQ (specifier, Vright_toolbar_width))
  637.     pos = RIGHT_TOOLBAR;
  638.   else
  639.     abort ();
  640.  
  641.   newval = f->toolbar_size[pos];
  642.  
  643.   /* We want the text area to stay the same size.  So, we query the
  644.      current size and then adjust it for the change in the toolbar
  645.      size. */
  646.  
  647.   in_specifier_change_function++;
  648.   if (!in_resource_setting)
  649.     /* mirror the value in the frame resources, unless it was already
  650.        done. */
  651.     XtVaSetValues (FRAME_X_TEXT_WIDGET (f),
  652.            pos == TOP_TOOLBAR ? XtNtopToolBarHeight :
  653.            pos == BOTTOM_TOOLBAR ? XtNbottomToolBarHeight :
  654.            pos == LEFT_TOOLBAR ? XtNleftToolBarWidth :
  655.            XtNrightToolBarWidth,
  656.            XINT (newval), 0);
  657.   if (XtIsRealized (FRAME_X_CONTAINER_WIDGET (f)))
  658.     {
  659.       int change = XINT (newval) - XINT (oldval);
  660.  
  661.       req.request_mode = 0;
  662.       /* the query-geometry method looks at the current value
  663.      of f->toolbar_size[pos], so temporarily set it back to the
  664.      old one. */
  665.       f->toolbar_size[pos] = oldval;
  666.       XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
  667.       f->toolbar_size[pos] = newval;
  668.       
  669.       if (change < 0)
  670.     x_clear_toolbar (f, pos, change);
  671.       if (pos == LEFT_TOOLBAR || pos == RIGHT_TOOLBAR)
  672.     repl.width += change;
  673.       else
  674.     repl.height += change;
  675.  
  676.       MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
  677.       EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
  678.                   repl.height);
  679.     }
  680.   in_specifier_change_function--;
  681. }
  682.  
  683. static void
  684. x_initialize_frame_toolbar_gcs (struct frame *f)
  685. {
  686.   EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
  687.   XGCValues gcv;
  688.   unsigned long flags = (GCForeground | GCBackground | GCGraphicsExposures);
  689.  
  690.   gcv.foreground = ef->emacs_frame.background_toolbar_pixel;
  691.   gcv.background = ef->core.background_pixel;
  692.   gcv.graphics_exposures = False;
  693.   FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f) =
  694.     XtGetGC ((Widget) ef, flags, &gcv);
  695.  
  696.   if (ef->emacs_frame.top_toolbar_shadow_pixel == -1)
  697.     {
  698.       ef->emacs_frame.top_toolbar_shadow_pixel =
  699.     ef->emacs_frame.background_toolbar_pixel;
  700.     }
  701.   if (ef->emacs_frame.bottom_toolbar_shadow_pixel == -1)
  702.     {
  703.       ef->emacs_frame.bottom_toolbar_shadow_pixel =
  704.     ef->emacs_frame.background_toolbar_pixel;
  705.     }
  706.  
  707.   x_generate_shadow_pixels (f, &ef->emacs_frame.top_toolbar_shadow_pixel,
  708.                 &ef->emacs_frame.bottom_toolbar_shadow_pixel,
  709.                 ef->emacs_frame.background_toolbar_pixel,
  710.                 ef->core.background_pixel);
  711.  
  712.   gcv.foreground = ef->emacs_frame.top_toolbar_shadow_pixel;
  713.   gcv.background = ef->core.background_pixel;
  714.   gcv.graphics_exposures = False;
  715.   flags = GCForeground | GCBackground | GCGraphicsExposures;
  716.   if (ef->emacs_frame.top_toolbar_shadow_pixmap)
  717.     {
  718.       gcv.fill_style = FillOpaqueStippled;
  719.       gcv.stipple = ef->emacs_frame.top_toolbar_shadow_pixmap;
  720.       flags |= GCStipple | GCFillStyle;
  721.     }
  722.   FRAME_X_TOOLBAR_TOP_SHADOW_GC (f) = XtGetGC ((Widget) ef, flags, &gcv);
  723.  
  724.   gcv.foreground = ef->emacs_frame.bottom_toolbar_shadow_pixel;
  725.   gcv.background = ef->core.background_pixel;
  726.   gcv.graphics_exposures = False;
  727.   flags = GCForeground | GCBackground | GCGraphicsExposures;
  728.   if (ef->emacs_frame.bottom_toolbar_shadow_pixmap)
  729.     {
  730.       gcv.fill_style = FillOpaqueStippled;
  731.       gcv.stipple = ef->emacs_frame.bottom_toolbar_shadow_pixmap;
  732.       flags |= GCStipple | GCFillStyle;
  733.     }
  734.   FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f) = XtGetGC ((Widget) ef, flags, &gcv);
  735.  
  736. #ifdef HAVE_XPM
  737.   FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f) =
  738.     FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
  739. #else
  740.   {
  741.     struct device *d = XDEVICE (f->device);
  742.     Display *dpy = DEVICE_X_DISPLAY (d);
  743.  
  744.     gcv.background = WhitePixelOfScreen (DefaultScreenOfDisplay (dpy));
  745.     gcv.foreground = BlackPixelOfScreen (DefaultScreenOfDisplay (dpy));
  746.     gcv.graphics_exposures = False;
  747.     flags = GCForeground | GCBackground | GCGraphicsExposures;
  748.     FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f) =
  749.       XtGetGC ((Widget) ef, flags, &gcv);
  750.   }
  751. #endif
  752. }
  753.  
  754. static void
  755. x_release_frame_toolbar_gcs (struct frame *f)
  756. {
  757.   Widget ew = (Widget) FRAME_X_TEXT_WIDGET (f);
  758.   XtReleaseGC (ew, FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f));
  759.   /* If compiled with XPM support, this is a pointer to the same GC as
  760.      FRAME_X_BLANK_BACKGROUND_GC so we need to make sure we don't
  761.      release it twice. */
  762. #ifndef HAVE_XPM
  763.   XtReleaseGC (ew, FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f));
  764. #endif
  765.   XtReleaseGC (ew, FRAME_X_TOOLBAR_TOP_SHADOW_GC (f));
  766.   XtReleaseGC (ew, FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f));
  767.  
  768.   /* Seg fault if we try and use these again. */
  769.   FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f) = (GC) -1;
  770.   FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f) = (GC) -1;
  771.   FRAME_X_TOOLBAR_TOP_SHADOW_GC (f) = (GC) -1;
  772.   FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f) = (GC) -1;
  773. }
  774.  
  775. static void
  776. x_initialize_frame_toolbars (struct frame *f)
  777. {
  778.   EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
  779.  
  780.   if (ef->emacs_frame.toolbar_shadow_thickness < MINIMUM_SHADOW_THICKNESS)
  781.     {
  782.       XtVaSetValues (FRAME_X_TEXT_WIDGET (f), XtNtoolBarShadowThickness,
  783.              MINIMUM_SHADOW_THICKNESS, 0);
  784.     }
  785.  
  786.   x_initialize_frame_toolbar_gcs (f);
  787. }
  788.  
  789. /* This only calls one function but we go ahead and create this in
  790.    case we ever do decide that we need to do more work. */
  791. static void
  792. x_free_frame_toolbars (struct frame *f)
  793. {
  794.   x_release_frame_toolbar_gcs (f);
  795. }
  796.  
  797.  
  798. /************************************************************************/
  799. /*                            initialization                            */
  800. /************************************************************************/
  801.  
  802. void
  803. device_type_create_toolbar_x (void)
  804. {
  805.   DEVICE_HAS_METHOD (x, output_frame_toolbars);
  806.   DEVICE_HAS_METHOD (x, initialize_frame_toolbars);
  807.   DEVICE_HAS_METHOD (x, free_frame_toolbars);
  808.   DEVICE_HAS_METHOD (x, output_toolbar_button);
  809.   DEVICE_HAS_METHOD (x, redraw_frame_toolbars);
  810.   DEVICE_HAS_METHOD (x, toolbar_size_changed_in_frame);
  811. }
  812.